package com.fantastic.sort;

import java.util.Arrays;

/**
 * @author : fantastic
 * @date : 2024/5/15 14:22
 * @desc : this class for xxxxx
 **/
public class ShellSort {

    public static void main(String[] args) {
        int[] arr = {20, 10, 11, 14, 9, 9, 10, 13};
        shellSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void shellSort(int[] arr){
        int gpa=arr.length/2;
        for (; gpa >0 ; gpa=gpa/2) {
            for (int i = 0; (i+gpa) < arr.length; i++) {
                for (int j = 0; (j+gpa) < arr.length; j+=gpa) {
                    if (arr[j]>arr[j+gpa]){
                        int temp=arr[j];
                        arr[j]=arr[j+gpa];
                        arr[j+gpa]=temp;
                    }
                }
            }
            
        }
    }
}
